package org.itcast.travel.controller;

import lombok.extern.slf4j.Slf4j;
import org.itcast.travel.pojo.Result;
import org.itcast.travel.pojo.Ticket;
import org.itcast.travel.pojo.TicketQueryParam;
import org.itcast.travel.service.TicketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/ticket")
public class TicketController {
    @Autowired
    public TicketService ticketService;
//    添加票
    @PostMapping
    public Result save(@RequestBody Ticket ticket) {
        log.info("数据：{}",ticket);
        ticketService.save(ticket);
        return Result.success();
    }
//    根据id删除
@DeleteMapping
    public Result delete(@RequestParam List<Integer> ids) {
        ticketService.deleteById(ids);
        return Result.success();
    }
    // 根据id查询
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        Ticket ticket = ticketService.getById(id);
        return Result.success(ticket);
    }
    //票修改
    @PutMapping
    public Result update(@RequestBody Ticket ticket) {
        ticketService.update(ticket);
        return Result.success();
    }
    @GetMapping
    public Result page(TicketQueryParam ticketQueryParam) {
        return Result.success(ticketService.page(ticketQueryParam));
    }
}
